package com.linkhub.oms.dao.mpservice.impl;

import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import com.linkhub.oms.entity.ShopProductEntity;
import com.linkhub.oms.dao.mapper.ShopProductEntityMapper;
import com.linkhub.oms.dao.mpservice.IShopProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商店商品表 服务实现类
 * </p>
 *
 * @author echo
 * @since 2024-03-20
 */
@Service
public class ShopProductServiceImpl extends ServiceImpl<ShopProductEntityMapper, ShopProductEntity> implements IShopProductService {

    @Override
    public void deleteShopProducts(String sysShopId, List<Long> productIds) {
        if (CollUtil.isEmpty(productIds)) {
            return;
        }
        super.lambdaUpdate()
                .eq(ShopProductEntity::getSysShopId, sysShopId)
                .in(ShopProductEntity::getProductId, productIds)
                .remove();
    }

    @Override
    public List<ShopProductEntity> listShopProducts(String sysShopId, List<Long> productIds) {
        if (CollUtil.isEmpty(productIds)) {
            return Lists.newArrayListWithCapacity(0);
        }

        return super.lambdaQuery()
                .eq(ShopProductEntity::getSysShopId, sysShopId)
                .in(ShopProductEntity::getProductId, productIds)
                .list();
    }

    @Override
    public ShopProductEntity getShopProductByProductName( String sysShopId, String productName ) {
        return super.lambdaQuery()
                .eq(ShopProductEntity::getSysShopId, sysShopId)
                .eq(ShopProductEntity::getTitle, productName)
                .one();
    }
}
